{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# python 2.7 test\n",
    "'''python\n",
    "'''\n",
    "import numpy as np\n",
    "x= np.array([1,3,1,3,5,6,2,4,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 (1, 3)\n",
      "1 3\n",
      "Matching error\n"
     ]
    }
   ],
   "source": [
    "# Return variable from a function\n",
    "def func(input):\n",
    "    cache1= 1\n",
    "    cache2= 3\n",
    "    cache = (cache1, cache2) \n",
    "    return input, cache\n",
    "input, cache= func(1)\n",
    "print input, cache\n",
    "cache1, cache2 = cache\n",
    "print cache1, cache2\n",
    "try:\n",
    "    input, cache1, cache2= func(-1)\n",
    "    print input, cache1, cache2\n",
    "except:\n",
    "    print \"Matching error\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 3 1]\n",
      " [3 5 6]\n",
      " [2 4 1]]\n",
      "6\n",
      "[[3]\n",
      " [6]\n",
      " [4]] keepdims=True\n"
     ]
    }
   ],
   "source": [
    "# max function\n",
    "x=x.reshape(3,3)\n",
    "print x\n",
    "print np.max(x)\n",
    "print np.max(x, axis=1, keepdims=True), \"keepdims=True\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 3 1]\n",
      " [3 5 6]\n",
      " [2 4 1]]\n",
      "[[3 5 4]\n",
      " [5 7 9]\n",
      " [4 6 4]] x+bias\n",
      "[[-1  1 -2]\n",
      " [ 1  3  3]\n",
      " [ 0  2 -2]] x-bias\n",
      "[3 3 4] bias+1\n"
     ]
    }
   ],
   "source": [
    "# adding operator\n",
    "x= x.reshape(3,3)\n",
    "bias= np.array([2,2,3])\n",
    "print x\n",
    "print x+bias, \"x+bias\"\n",
    "print x-bias, \"x-bias\"\n",
    "print bias+1, \"bias+1\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 3 2 1]\n",
      " [2 0 1 1]]\n",
      "[[3]\n",
      " [2]]\n",
      "0.367879441171 0.135335283237 0.0497870683679 references\n",
      "[[ 0.13533528  1.          0.36787944  0.13533528]\n",
      " [ 1.          0.13533528  0.36787944  0.36787944]]\n"
     ]
    }
   ],
   "source": [
    "# numpy.max() add operator\n",
    "import numpy as np\n",
    "x= np.array([[1,3,2,1],[2,0,1,1]])\n",
    "probs = np.exp(x - np.max(x, axis=1, keepdims=True))\n",
    "print x\n",
    "print np.max(x, axis=1, keepdims=True)\n",
    "print np.exp(-1), np.exp(-2), np.exp(-3), \"references\"\n",
    "print probs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "# python class\n",
    "class TwoLayerNet(object):\n",
    "    def __init__(self, value):\n",
    "        self.param= value\n",
    "    def test(self):\n",
    "        print self.param\n",
    "obj= TwoLayerNet(2)\n",
    "obj.test()"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
